package com.lin.codesandbox.controller;

import com.lin.codesandbox.codesandbox.JavaNativeCodeSandbox;
import com.lin.codesandbox.codesandbox.model.ExecuteCodeRequest;
import com.lin.codesandbox.codesandbox.model.ExecuteCodeResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController("/")
public class MainController {
    @Resource
    private JavaNativeCodeSandbox javaNativeCodeSandbox;
    @GetMapping("/health")
    public String healthCheck(){
        return "ok";
    }

    @GetMapping("/t1")
    public String test01(){
        return "test01";
    }
    @GetMapping("/t2")
    public String test02(){
        return "test02";
    }
    @GetMapping("/t3")
    public String test03(){
        return "test03";
    }

    @PostMapping("/executeCode")
    ExecuteCodeResponse executeCode(@RequestBody ExecuteCodeRequest executeCodeRequest){
        if(executeCodeRequest == null){
            throw new RuntimeException("请求参数为空");
        }
        return javaNativeCodeSandbox.executeCode(executeCodeRequest);
    }
}
